/* $Id: FTDLFont.java 35 2006-09-26 20:24:50Z funsheep $ */
package net.sourceforge.ftgl.glfont;

import java.awt.Font;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.Point2D;

import net.sourceforge.ftgl.glyph.FTDLGlyph;
import net.sourceforge.ftgl.glyph.FTGlyph;
import net.sourceforge.ftgl.math.FTStringMetrics;

/**
 * @author funsheep
 *
 */
public abstract class FTDLFont extends FTFont
{


	/**
	 * @param fontname
	 */
	public FTDLFont(String fontname)
	{
		super(fontname);
	}

	/**
	 * @param font
	 */
	public FTDLFont(Font font)
	{
		super(font);
	}

	/**
	 * @param fontname
	 * @param context
	 */
	public FTDLFont(String fontname, FontRenderContext context)
	{
		super(fontname, context);
	}

	/**
	 * @param font
	 * @param context
	 */
	public FTDLFont(Font font, FontRenderContext context)
	{
		super(font, context);
	}


	public FTStringMetrics render(String string, boolean preventDLCreation)
	{
		//this code is completely copied from FTFont.render(string) - dont know, how to do it better...
		final GlyphVector vec = this.font.layoutGlyphVector(this.fontrendercontext, string.toCharArray(), 0, string.length(), this.fontFlags);

		Point2D old = new Point2D.Float();
		for (int i = 0; i < vec.getNumGlyphs(); i++)
		{
			final Point2D p = vec.getGlyphPosition(i);
			final FTGlyph glyph = this.checkGlyph(vec.getGlyphCode(i), vec.getGlyphOutline(i, (float) -p.getX(), (float) p.getY()));

			final float xDif = (float) (p.getX() - old.getX());
			final float yDif = (float) (p.getY() - old.getY());
			((FTDLGlyph) glyph).render(xDif, yDif, 0.0f, preventDLCreation);
			assert renderFTBBox(glyph.getBBox(), 0f, 0f, 0f, this.gl);
			old = p;
		}
		old = vec.getGlyphPosition(vec.getNumGlyphs());
		return new FTStringMetrics(string, null, (float) old.getX(), (float) old.getY());
	}

}
